<template>
  <div class="container">
    <div class="user-img">
      <!-- <img src="../../assets/img/img.jpg" /> -->
    </div>
    <div class="user-name">{{username.realname}}</div>
    <van-cell-group>
      <van-field
        v-model="username.account"
        label="账号"
        disabled
      />
      <van-field
        v-model="oldPassword"
        required
        label="原密码"
        placeholder="请输入原密码"
        type="password"
      />
      <van-field
        v-model="password"
        required
        label="密码"
        placeholder="请输入密码"
        type="password"
      />
      <van-field
        v-model="agePassword"
        required
        label="确认密码"
        placeholder="请输确认密码"
        type="password"
      />
      <p style="font-size:12px;color:red;text-align:right;background-color:#fff;padding:10px;">提示：密码不少于6位数</p>
    </van-cell-group>
    <van-button type="info" style="margin-top:20px;" block round @click="submit">确认</van-button>
  </div>
</template>
<script>
import bus from '@/common/bus';
import notFind from "@/view/common/notFind";
import {Icon,Popup,Toast,DropdownMenu, DropdownItem,Search,Button,Pagination,Field,CellGroup} from 'vant';
export default {
  name: "mobileRestAdmin",
  components:{notFind,[Icon.name]: Icon,[CellGroup.name]: CellGroup,[Field.name]: Field,[Popup.name]: Popup,[DropdownMenu.name]: DropdownMenu,[DropdownItem.name]: DropdownItem,[Search.name]:Search,[Button.name]:Button,[Pagination.name]:Pagination},
  data() {
    return {
      oldPassword:'',
      password: '',
      agePassword:'',
      userInfo:""
    };
  },
  computed: {
    username () {
      let userInfo = localStorage.getItem('userInfo');
      this.userInfo=JSON.parse(userInfo);
      return userInfo ? JSON.parse(userInfo) : {realname:this.name};
    }
  },
  methods: {
    submit(){
      if(this.password.trim() !== this.agePassword.trim()){
          return Toast.fail('两次输入密码不一致请重新输入');
      }
      if(this.oldPassword.trim().length<6){
        return Toast.fail('请输入大于6位数密码！');
      }

      if(this.password.trim().length<6){
        return Toast.fail('请输入大于6位数密码！');
      }
      Toast.loading({ message: "加载中...", forbidClick: true });
      let url=this.$API.SET_PASSWORDv2;
      url+="?oldPassword="+this.oldPassword+"&newPassword="+this.password+"&id="+this.userInfo.id
      this.$http
        .put(url,{id:this.userInfo.id,oldPassword:this.oldPassword,newPassword:this.password,rawPassword :this.agePassword})
        .then((res) => {
          Toast.clear();
          if (res.code == 1) {
              Toast.success('修改成功');
              setTimeout(()=>{
                  this.$router.push('./login');
                  // this.$router.push('/login');
              },1000)
          }else{
            Toast.fail(res.message);
          }
      })
    }
  },
};
</script>
<style lang="less" scoped>
.container{
  padding:10% 20px 0 20px;
  background: #fafafa;
}
.user-img{
  display: flex;
  align-items: center;
  justify-content: center;
  img{
    width: 100px;
    height: 100px;
    border-radius: 50%;
    overflow: hidden;
  }
}
.user-name{
  font-size: 14px;
  color:#888;
  text-align: center;
  padding: 10px;
}
</style>


